<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '340px'
    },
    autoResize: {
      type: Boolean,
      default: true
    },
    chartData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val)
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      // this.setOptions(this.chartData)
      this.setOptions()
    },
    // setOptions({ expectedData, actualData } = {}) {
    setOptions() {
      this.chart.setOption({

        grid: {
          left: 30,
          right: 20,
          bottom: 20,
          top: 30
          // containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          padding: [5, 10]
        },
        xAxis: {
          data: ['一', '二', '三', '四', '五', '六', '七', '八'],
          boundaryGap: false,
          axisTick: {
            show: false
          },
          axisLabel: {
            textStyle: {
              color: '#4A5A7F'
            }
          }
        },
        yAxis: {
          axisTick: {
            show: false
          },
          axisLabel: {
            textStyle: {
              color: '#4A5A7F'
            }
          }
        },

        series: [

          {
            name: '医保人数',
            symbol: 'none',
            itemStyle: {
              normal: {
                color: '#518CF6',
                lineStyle: {
                  color: '#518CF6',
                  width: 2
                  // shadowColor: 'rgba(0,0,0,0.2)', // 设置折线阴影
                  // shadowBlur: 10,
                  // shadowOffsetY: 10
                }
              }
            },
            smooth: true,
            areaStyle: {
              normal: {
                color: '#F7F9FF'

              }
            },
            type: 'line',
            data: [966, 12, 23, 588, 889, 23, 123, 152],
            animationDuration: 2800,
            animationEasing: 'cubicInOut'
          }
        ]
      })
    }
  }
}
</script>
